package com.mdd.admin.controller.competition;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICompetitionService;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.competition.CompetitionScheduleCreateValidate;
import com.mdd.admin.validate.competition.CompetitionScheduleSearchValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.competition.CompetitionMatch;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/adminapi/competition/schedule")
public class CompetitionScheduleController {

    @Resource
    ICompetitionService competitionService;

    @GetMapping("/lists")
    @ApiOperation(value="赛事列列表")
    public AjaxResult<PageResult<Map>> scheduleList(@Validated PageValidate pageValidate,
                                                            @Validated CompetitionScheduleSearchValidate searchValidate) {
        PageResult<Map> list = competitionService.scheduleList(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="赛事列详情")
    public AjaxResult detail(@RequestParam(value = "id",required = false) Integer id) {
        CompetitionMatch detail = competitionService.scheduleDetail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "赛事列编辑")
    @PostMapping("/edit")
    @ApiOperation(value="赛事列编辑")
    public AjaxResult edit(@Validated @RequestBody CompetitionScheduleCreateValidate updateValidate) {
        competitionService.scheduleEdit(updateValidate);
        return AjaxResult.success();
    }

}
